// 返回数据并进行索引建立
console.log("计算结束之前", data);


let plugins = getLocalValue("plugins");
let PointSimplifier = plugins.PointSimplifier;
//存储全局变量中，实现对应逻辑
let mapStatus = getLocalValue("mapStatus");
mapStatus.AvoidLayerData = data;

console.log(plugins);


var defaultRenderOptions = {
  devicePixelRatio: 1,
  drawQuadTree: false,
  drawPositionPoint: false,
  drawShadowPoint: false,
  //点
  pointStyle: {
    content: 'circle',
    width: 6,
    height: 6,
    fillStyle: '#1f77b4',
    lineWidth: 1,
    strokeStyle: 'rgba(0,0,0,0)'
  },
  //TopN区域
  topNAreaStyle: {
    autoGlobalAlphaAlpha: true,
    content: 'rect',
    fillStyle: '#e25c5d',
    lineWidth: 1,
    strokeStyle: 'rgba(0,0,0,0)'
  },
  //点的硬核部分
  pointHardcoreStyle: {
    content: 'none',
    // width: 5,
    // height: 5,
    // width: 58,
    // height: 64,
    width: 48,
    height: 48,
    lineWidth: 1,
    fillStyle: 'rgba(0,0,0,0)',
    strokeStyle: 'rgba(0,0,0,0)'
  },
  //定位点
  pointPositionStyle: {
    content: 'circle',
    width: 2,
    height: 2,
    lineWidth: 1,
    //offset: ['-50%', '-50%'],
    strokeStyle: 'rgba(0,0,0,0)',
    fillStyle: '#cc0000'
  },
  //鼠标hover时的覆盖点
  pointHoverStyle: {
    width: 10,
    height: 10,
    content: 'circle',
    fillStyle: 'rgba(0,0,0,0)',
    lineWidth: 2,
    strokeStyle: '#ffa500'
  },
  //空间被占用的点
  shadowPointStyle: {
    fillStyle: 'rgba(0,0,0,0.2)',
    content: 'circle',
    width: 6,
    height: 6,
    lineWidth: 1,
    strokeStyle: 'rgba(0,0,0,0)'
  }
};


var pPointSimplifier = new PointSimplifier({
  zIndex: 100,
  // map: map,
  getPosition: function (item) {

    if (!item) {
      return null;
    }

    // var parts = item.split(',');

    // return [parseFloat(parts[0]), parseFloat(parts[1])];
    // return [item.lng, item.lat, item.name];
    return [parseFloat(item.lng), parseFloat(item.lat), item.name];
  },
  compareDataItem: function (a, b, aIndex, bIndex) {

    //数据源尾部的优先
    return aIndex > bIndex ? -1 : 1;
  },
  getHoverTitle: function (dataItem, idx) {
    return idx + ': ' + dataItem;
  },
  renderOptions: defaultRenderOptions
});
pPointSimplifier.setData(mapStatus.AvoidLayerData);

mapStatus.AvoidLayer_pointSim = pPointSimplifier;
console.log("mapStatus.AvoidLayer_pointSim" + mapStatus.AvoidLayer_pointSim)

console.log("mapStatus.AvoidLayer_pointSim" + getLocalValue("zoom") + getLocalValue("lng") + getLocalValue("lat"))


// 加载完成主动触发 数据避让一次
// 中心点及zoom值
// let mapStatus = getLocalValue("mapStatus")
let zoom = mapStatus.currentZoom;
let lng = mapStatus.currentCenterLng;
let lat = mapStatus.currentCenterLat;
console.log("mapStatus是否存在1", mapStatus)
return {
  zoom: zoom,
  lng: lng,
  lat: lat,
}; 